home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5d6 / dcmds / C Samples / Vol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-17  |  4.7 KB  |  207 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Vol.c
  3.  
  4.     Contains:    This is the Vol dcmd.
  5.  
  6.     Written by:    Scott Douglas, Dave Lyons.
  7.  
  8.     Copyright:    © 1988,1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     9/10/93    DAL        Fixed volume-name matching to work again (was using
  13.                                     non-prototyped "EQUALSTRING" instead of EqualString).  Widened
  14.                                     the volume-name column.  Changed "VCB at" to "VCB addr" and made
  15.                                     it align for 32-bit addresses.
  16.  
  17.     Modification history:
  18.         29Nov88 sad        revised for new dcmd names.  display more info.
  19.          5Oct88 sad        written.
  20.  
  21.     The following MPW commands will build the dcmd and copy it to the
  22.     "Debugger Prefs" file in the System folder. The dcmd's name in
  23.     MacsBug will be the name of the file built by the Linker.
  24.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  25.     C Samples folder into this folder.
  26.  
  27.     C Put.c
  28.     C Vol.c
  29.     Link dcmdGlue.a.o Vol.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Vol
  30.     BuildDcmd Vol 1002
  31.     Echo 'include "Vol";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  32. */
  33.  
  34. #include <Types.h>
  35. #include <Memory.h>
  36. #include <OSUtils.h>
  37. #include <Files.h>
  38.  
  39. #include "dcmd.h"
  40. #include "put.h"
  41.  
  42. #define VCBQHdr ((QHdrPtr)0x356)
  43.  
  44.  
  45. static void DrawHdr()
  46. {
  47. //                             1         2         3         4         5         6         7
  48. //                    1234567890123456789012345678901234567890123456789012345678901234567890123456789
  49.     dcmdDrawLine("\pvRef Vol                  Flg dRef Drive FSID #Blk BlkSiz #Files #Dirs  Blsd Dir VCB addr");
  50. }
  51.  
  52.  
  53. static void DrawVCB(VCB* vcbp)
  54. {
  55.     PutUHexWord(vcbp->vcbVRefNum);
  56.     PutSpace();
  57.     PutPStrTruncTo(vcbp->vcbVN,15+10);
  58.     PutSpace();
  59.     PutChar((vcbp->vcbFlags & 0x8000) ? 'D' : 'd');
  60.     PutChar((vcbp->vcbAtrb & 0x8000) ? 'S' : 's');
  61.     PutChar((vcbp->vcbAtrb & 0x4000) ? 'H' : 'h');
  62.     PutSpace();
  63.     PutUHexWord(vcbp->vcbDRefNum);
  64.     PutSpace();
  65.     PutSpace();
  66.     PutUHexWord(vcbp->vcbDrvNum);
  67.     PutSpace();
  68.     PutUHexWord(vcbp->vcbFSID);
  69.     PutSpace();
  70.     PutUHexWord(vcbp->vcbNmAlBlks);
  71.     PutSpace();
  72.     PutUHexZTo(vcbp->vcbAlBlkSiz,6,47+10);
  73.     PutSpace();
  74.     PutUHexZTo(vcbp->vcbFilCnt,6,54+10);
  75.     PutSpace();
  76.     PutUHexZTo(vcbp->vcbDirCnt,6,61+10);
  77.     PutSpace();
  78.     PutUHexZTo(vcbp->vcbFndrInfo[0],6,70+10);
  79.     PutSpace();
  80.     PutUHexZTo((unsigned long)vcbp,8,77+10);
  81.     PutLine();
  82. }
  83.  
  84.  
  85. // PrefixPStr
  86. //
  87. // Returns true if astr is equal to a prefix of bstr.
  88. // astr must not be longer than 31 characters.
  89.  
  90. static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
  91. {
  92.     char newstr[32];
  93.     int alen = *astr;
  94.     int blen = *bstr;
  95.  
  96.     if (alen <= blen)
  97.       {
  98.         BlockMove(bstr+1,newstr+1,alen);
  99.         newstr[0] = alen;
  100.         return EqualString(astr,newstr,false,true);
  101.       }
  102.  
  103.     return false;    
  104. }
  105.  
  106.  
  107.  
  108. pascal void CommandEntry(dcmdBlock* paramPtr)
  109. {
  110.     switch (paramPtr->request)
  111.       {
  112.         case dcmdInit:
  113.             break;
  114.  
  115.         case dcmdHelp:
  116.             dcmdDrawLine("\pvol [vRefNum|drvNum|\"vol name\"]");
  117.             dcmdDrawLine("\p   Displays volume information for the given vrefnum, volume name or all mounted volumes.");
  118.             dcmdDrawLine("\p      Flags are D/d=Dirty, S/s=Software locked, H/h=Hardware locked.");
  119.             break;
  120.  
  121.         case dcmdDoIt:
  122.           {
  123.             Boolean doOneVCB = false;
  124.             long vref;
  125.             short c;
  126.             Boolean haveVolName = false;
  127.             Str255 volname;
  128.             VCB* vcbp;
  129.             int numvcbs = 0;
  130.             Boolean foundOne = false;
  131.  
  132.             dcmdSwapWorlds();
  133.  
  134.             dcmdDrawLine("\pDisplaying Volume Control Blocks");
  135.  
  136.             // get low-memory values after dcmdSwapWorlds()
  137.             vcbp = (VCB*) (VCBQHdr->qHead);
  138.  
  139.             c = dcmdPeekAtNextChar();
  140.             if (c == '"' || c == '\'')
  141.               {
  142.                 haveVolName = true;
  143.                 (void) dcmdGetNextParameter(volname);
  144.               }
  145.             else
  146.                 (void) dcmdGetNextExpression(&vref, &doOneVCB);
  147.  
  148.             if (doOneVCB)
  149.                 vref = (short) vref;
  150.  
  151.             while (vcbp)
  152.               {
  153.                 if ((doOneVCB && (vcbp->vcbVRefNum == vref || vcbp->vcbDrvNum == vref)) ||
  154.                     (haveVolName && PrefixPStr(volname,vcbp->vcbVN)) ||
  155.                     (!doOneVCB && !haveVolName))
  156.                   {
  157.                     numvcbs++;
  158.                     if (!foundOne)
  159.                       {
  160.                         DrawHdr();
  161.                         foundOne = true;
  162.                       }
  163.                     DrawVCB(vcbp);
  164.                   }
  165.                 if (paramPtr->aborted) break;
  166.                 if (vcbp->qLink == 0)
  167.                     if (vcbp != (VCB*)(VCBQHdr->qTail))
  168.                         dcmdDrawLine("\pVCB queue does not end at VCBQHdr.qTail");
  169.                 vcbp = (VCB*)vcbp->qLink;
  170.               }
  171.             if (!paramPtr->aborted)
  172.                 if (haveVolName || doOneVCB)
  173.                   {
  174.                     if (!foundOne)
  175.                         if (haveVolName)
  176.                           {
  177.                             PutPStr("\pNo mounted volumes match \"");
  178.                             PutPStr(volname);
  179.                             PutChar('"');
  180.                             PutLine();
  181.                           }
  182.                         else
  183.                           {
  184.                             PutPStr("\pNo mounted volumes match ");
  185.                             PutUHexWord(vref);
  186.                             PutLine();
  187.                           }
  188.                   }
  189.                 else
  190.                   {
  191.                     PutUDec(numvcbs);
  192.                     PutPStr("\p VCBs");
  193.                     PutLine();
  194.                   }
  195.  
  196.             dcmdSwapWorlds();
  197.             break;
  198.           }
  199.  
  200.         default:
  201.             PutPStr("\punknown request ");
  202.             PutUDec(paramPtr->request);
  203.             PutLine();
  204.             break;
  205.       }
  206. } // CommandEntry
  207.